package fjut.acm.coding.component.judge.data;

public enum StatusType {


    JUDGING(0,"JUDGING"),
    AC(1,"Accepted"),
    WA(2,"Wrong Answer"),
    CE(3,"Compilation Error"),
    RE(4,"Runtime Error"),
    TLE(5,"Time Limit Exceeded"),
    MLE(6,"Memory Limit Exceeded"),
    OLE(7,"Output Limit Exceeded"),
    PE(8,"Presentation Error"),
    SE(9,"System Error"),
    ERROR(10,"ERROR"),
    PENDING(11,"PENDING"),
    SC(12,"Score");



    private int code;
    private String name;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    StatusType(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public boolean isAc() {
        return this == StatusType.AC;
    }

    public boolean isErr() {
        return this ==  StatusType.WA ||
                this ==  StatusType.CE ||
                this ==  StatusType.RE ||
                this ==  StatusType.TLE ||
                this ==  StatusType.MLE ||
                this ==  StatusType.OLE ||
                this ==  StatusType.PE;
    }

    public boolean isPd() {
        return this ==  StatusType.PENDING ||
                this == StatusType.ERROR ||
                this == StatusType.JUDGING;
    }

    public static String getNameByCode(int code) {
        for ( StatusType r :  StatusType.values()) {
            if (code == r.getCode()) {
                return r.getName();
            }
        }
        return null;
    }

    public static Integer getCodeByName(String name) {
        for ( StatusType r :  StatusType.values()) {
            if (name.equals(r.getName())) {
                return r.getCode();
            }
        }
        return null;
    }

}
